let app = getApp();

class Base {
    constructor() {
        this.baseRequestUrl = ''
    }

    request(params) {
        let that = this;
        app.util.request({
            url: params.url,
            data: params.data,
            method: params.type,
            showLoading: params.showLoading,
            header: params.header,
            success: function (res) {
                params.sCallback && params.sCallback(res);
            },
            fail: function (err) {
                that._processError(err);
            }
        })
    }

    _processError(err) {
        if (err.data.code != -1 && err.data.code != 404 && err.data.code != 700) {
            wx.showModal({
                title: '提示',
                content: err.data.msg,
                success: function (res) {
                    if (res.confirm) {
                        console.log('用户点击确定')
                    } else if (res.cancel) {
                        console.log('用户点击取消')
                    }
                }
            })
        }
    }

    /*获得元素上的绑定的值*/
    getDataSet(event, key) {
        return event.currentTarget.dataset[key];
    }
}

export {Base};